﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;
using LTJ.FrameWork;

namespace LTJ.WebPage.UserManage.route
{
    /// <summary>
    /// 全部外部公司运价查看
    /// </summary>
    public partial class allotherroutelist : UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDataGrid();
            }
        }

        protected void BindDataGrid()
        {
            string strWhere = "";

            if (ViewState["condition"] == null || ViewState["condition"].ToString() == "")
            {
                strWhere = "cid <> " + companyinfo.id;
            }
            else
            {
                strWhere = "cid <> " + companyinfo.id + " AND " + ViewState["condition"].ToString();
            }

            DataGrid1.VirtualItemCount = RouteBases.GetRouteBaseListCount(2, companyinfo.id, strWhere);
            DataGrid1.DataSource = RouteBases.GetRouteBaseSearchTableByPage(2, companyinfo.id, -1, DataGrid1.CurrentPageIndex + 1, DataGrid1.PageSize, strWhere, "", "");
            DataGrid1.DataBind();
        }

        protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            DataGrid1.CurrentPageIndex = e.NewPageIndex;
            BindDataGrid();
        }

        protected void GoToPagerButton_Click(object sender, EventArgs e)
        {
            BindDataGrid();
        }

        /// <summary>
        /// 搜索点击
        /// </summary>
        protected void check_Click(object sender, EventArgs e)
        {
            string loadstr = loadport.Text;
            string deststr = destport.Text;
            string routestr = SASRequest.GetString("ajaxroutelinedatalist_value");
            string boatstr = SASRequest.GetString("ajaxcarrierlist_value");
            int searchcid = SASRequest.GetInt("ajaxcorpdatalist_value", 0);
            ViewState["condition"] = RouteBases.GetRouteBaseCondation(searchcid, 2, loadstr, deststr, routestr, boatstr);
            DataGrid1.CurrentPageIndex = 0;
            BindDataGrid();
        }

        /// <summary>
        /// 重新绑定
        /// </summary>
        protected void reclick_Click(object sender, EventArgs e)
        {
            BindDataGrid();
        }

        /// <summary>
        /// 其他价格生成
        /// </summary>
        protected string GetOtherPrice(string price, int ordernum)
        {
            string[] pricearray = price.Split(',');

            if (pricearray.Length < 3) return Utils.StrToInt(price, 0).ToString();
            else return pricearray[ordernum - 1] == "" ? "0" : pricearray[ordernum - 1];
        }

        protected string GetSeaPrce(System.Data.DataRow objDR, string columnstr)
        {
            float price1 = TypeConverter.StrToFloat(objDR[columnstr], 0);
            string numstr = "1,2,5,6";

            foreach (string str in numstr.Split(','))
            {
                if (SumPrice(objDR["20GP" + str].ToString(), objDR["40GP" + str].ToString(), objDR["40HQ" + str].ToString()) > 0) return (price1 + TypeConverter.StrToInt(objDR[columnstr + str].ToString(), 0)).ToString();
            }

            return price1.ToString();
        }

        private int SumPrice(string p1, string p2, string p3)
        {
            int price1 = TypeConverter.StrToInt(p1, 0);
            int price2 = TypeConverter.StrToInt(p2, 0);
            int price3 = TypeConverter.StrToInt(p3, 0);

            return price1 + price2 + price3;
        }

        #region Web 窗体设计器生成的代码

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            ViewState["condition"] = RouteBases.GetRouteBaseCondation(0, 2, "", "", "", "");

            DataGrid1.PageIndexChanged += new DataGridPageChangedEventHandler(DataGrid1_PageIndexChanged);
            DataGrid1.GoToPagerButton.Click += new EventHandler(GoToPagerButton_Click);
            DataGrid1.AllowCustomPaging = true;
            DataGrid1.TableHeaderName = "其他公司线路信息";
            DataGrid1.Attributes.Add("borderStyle", "0");
            DataGrid1.DataKeyField = "id";
            DataGrid1.ColumnSpan = 12;
            DataGrid1.SaveDSViewState = true;

            check.Click += new EventHandler(check_Click);
            reclick.ServerClick += new EventHandler(reclick_Click);
        }

        #endregion
    }
}